home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Controls / Visual Basic Controls.iso / vbcontrol / cstwnd / custxamp.cpp < prev    next >
C/C++ Source or Header  |  1993-12-29  |  6KB  |  243 lines

  1. #include "bar.h"
  2. #include "xampids.h"
  3. #include <listbox.h>
  4. #include <bitover.h>
  5. #include <nradio.h>
  6. #include <ccheck.h>
  7. #include <extras.h>
  8. #include <stdlib.h>
  9.  
  10. #define NF_Message WM_USER + 5
  11. class TCustXAmp : public TApplication
  12. {
  13.     CustColors    Colors;
  14.    CustCursors    Cursors;
  15. public:
  16.   TCustXAmp(LPSTR AName, HINSTANCE hInstance, HINSTANCE hPrevInstance,
  17.                    LPSTR lpCmdLine, int nCmdShow)
  18.     : TApplication(AName, hInstance, hPrevInstance, lpCmdLine, nCmdShow) {};
  19.     virtual void InitMainWindow();
  20. };
  21.  
  22. class TTellParent : public TCustomWindow
  23. {
  24.     int NMsg, Id;
  25. public:
  26.     TTellParent(PTWindowsObject AParent, LPSTR ATitle,
  27.        PCustColors Colors, PCustCursors ACursors,
  28.         int NotifMessage, int AnId)
  29.         : TCustomWindow(AParent, ATitle, Colors,ACursors),
  30.       TUnderlying(Colors, ACursors)
  31.         {    NMsg = NotifMessage;
  32.             Id = AnId; };
  33.     ~TTellParent() { };
  34.     virtual void WMClose(RTMessage Msg) = [WM_FIRST + WM_CLOSE]
  35.         {  Chars.Closing = TRUE;
  36.             SendMessage(Parent->HWindow, NMsg, Id, 0l); };
  37. };
  38.  
  39. // Declare TMainWindow, a TDialog descendant
  40. class TMainWindow : public TBarDialog, public TBitOver 
  41. {
  42.     PTListBox    List;
  43.     TTellParent*    ChildWind;
  44.     char IsWind;
  45.    HINSTANCE Data;
  46.     PTNCCharButton    NCBtns[2];
  47.    PTNCRadioButton NCRadios[2];
  48.     PTCRadio    TheRadio;
  49.    PTCCheck TheCheck;
  50. public:
  51.    TMainWindow(PTWindowsObject AParent, LPSTR AName,
  52.         PCustColors AColors, PCustCursors ACursors);
  53.     ~TMainWindow();
  54.  
  55.     virtual void Window(RTMessage) = [ID_FIRST + ID_WINDOW];
  56.     virtual void Nofication(RTMessage Msg) = [NF_Message]
  57.        {    delete ChildWind;
  58.             IsWind = FALSE;    };
  59.     virtual void SetupWindow();
  60.  
  61.    virtual void NCButton1(RTMessage) = [ID_FIRST + ID_NCBUTTON + 0];
  62.     virtual void NCButton2(RTMessage) = [ID_FIRST + ID_NCBUTTON + 1];
  63.     virtual void NCRadio(RTMessage) = [ID_FIRST + ID_NCBUTTON + 2];
  64.  
  65.     virtual void WMTimer(RTMessage) = [WM_FIRST + WM_TIMER];
  66. };
  67.  
  68. void TCustXAmp::InitMainWindow()
  69. {
  70.    //The Custom windows classes take a copy of the
  71.     //specified colors and cursors
  72.     Colors.OrigClassDefaults();
  73.     Colors.StaticText = RGB(0,255,255);
  74.     Colors.TitleBarActive = GetSysColor(COLOR_ACTIVECAPTION);
  75.     Colors.TitleBarInactive = GetSysColor(COLOR_INACTIVECAPTION);
  76.  
  77.     Cursors.OrigClassDefaults();
  78.     MainWindow = new TMainWindow(NULL, "XAMP_DLG",
  79.        &Colors, &Cursors);
  80. }
  81.  
  82. TMainWindow::TMainWindow(PTWindowsObject AParent, LPSTR AName,
  83.         PCustColors AColors, PCustCursors ACursors)
  84.         : TBarDialog(AParent, AName, AColors, ACursors),
  85.         TUnderlying(AColors, ACursors)
  86. {
  87.     List = new TListBox(this, ID_LISTBOX);
  88.     TheRadio = new TCRadio(this, 104, NULL);
  89.     TheCheck = new TCCheck(this, 105, NULL);
  90.  
  91.    Data = GetCustWindInstance();
  92.     SetBitmap(Data, "BACK_BRICK");
  93. }
  94.  
  95.  
  96. TMainWindow::~TMainWindow()
  97. {
  98.     DeleteExtendedButtons();
  99.  
  100.     KillTimer(HWindow, 0);
  101.  
  102.     delete TheRadio;
  103.     delete TheCheck;
  104.  
  105.     delete List;
  106.     if(IsWind)    delete ChildWind;
  107.  
  108.     for(int i=0;i<2;i++)
  109.         {
  110.         delete NCBtns[i];
  111.         delete NCRadios[i];
  112.       }
  113. }
  114.  
  115. void TMainWindow::SetupWindow()
  116. {
  117.     TCustomDialog::SetupWindow();
  118.     AddExtendedButtons(Data,1);
  119.  
  120.     RECT ARect;
  121.     char BText[8];
  122.     
  123.     for(int i=0;i<2;i++)
  124.         {
  125.         AreaFromTopLeft(ARect,i+1);
  126.  
  127.       wsprintf(BText,"%c",'1'+i);
  128.         NCBtns[i] = new TNCCharButton(HWindow, ARect,
  129.             ID_NCBUTTON + i,Data, BText);
  130.         AddNCButton(NCBtns[i]);
  131.       }
  132.     for(i=2;i<4;i++)
  133.         {
  134.         AreaFromTopLeft(ARect,i+1);
  135.  
  136.         switch(i)
  137.             {
  138.             case 2:
  139.                 NCRadios[i-2] = new TNCRadioButton(HWindow, ARect,
  140.                     ID_NCBUTTON + i,Data, "CHK_BLUELIGHT",
  141.                     "CHK_BLUEOFF", TRUE, TRUE);
  142.                 break;
  143.             case 3:
  144.                 NCRadios[i-2] = new TNCRadioButton(HWindow, ARect,
  145.                     ID_NCBUTTON + i,Data, "CHK_GREENLIGHT",
  146.                     "CHK_GREENOFF", FALSE, TRUE);
  147.                 break;
  148.          }
  149.  
  150.         AddNCButton(NCRadios[i-2]);
  151.       }
  152.  
  153.     GetModule()->MakeWindow(List);
  154.  
  155.    char Text[40];
  156.     for(i=0;i<20;i++)
  157.        {
  158.         wsprintf(Text,"Line %d",i);
  159.       List->AddString(Text);
  160.       }
  161.  
  162.     SetTimer(HWindow, 0, 500, NULL);
  163. }
  164.  
  165. void TMainWindow::WMTimer(RTMessage)
  166. {
  167.    NCRadios[1]->SetState(!NCRadios[1]->GetState());
  168.     DrawNCButton(ID_NCBUTTON + 3);
  169. }
  170.  
  171. void TMainWindow::Window(RTMessage)
  172. {
  173.    if(IsWind)
  174.         delete ChildWind;
  175.  
  176.     CustColors Colors;
  177.    Colors.WindowsDefaults();
  178.  
  179.    CustCursors Cursors;
  180.    Cursors.OrigClassDefaults();
  181.  
  182.    ChildWind = new TTellParent(this,
  183.        "Custom Window Test", &Colors, &Cursors,
  184.         NF_Message, 201);
  185.     ChildWind->Attr.Style = WS_POPUP | WS_BORDER |
  186.         WS_CAPTION | WS_VISIBLE | WS_SYSMENU |
  187.         WS_MINIMIZEBOX | WS_THICKFRAME;
  188.     ChildWind->Attr.W = 250;
  189.    ChildWind->Attr.H = 100;
  190.  
  191.    GetModule()->MakeWindow(ChildWind);
  192.  
  193.     IsWind = TRUE;
  194. }  
  195.  
  196. //Windows Entry Point
  197. int PASCAL WinMain(HINSTANCE hInstance,
  198.     HINSTANCE hPrevInstance, LPSTR lpCmdLine, int nCmdShow)
  199. {
  200.     TCustXAmp ACustXAmp("",hInstance, hPrevInstance,
  201.            lpCmdLine, nCmdShow);
  202.     ACustXAmp.Run();
  203.  
  204.     return ACustXAmp.Status;
  205. }
  206.  
  207. void TMainWindow::NCButton1(RTMessage)
  208. {
  209.     char Text[1000];
  210.                             
  211.     wsprintf(Text,"Size of TUnderlying: %d\n\r"
  212.         "Size with TBitOver: %d\n\r"
  213.         "Size of TNCButton: %d\n\r",
  214.         sizeof(TUnderlying),sizeof(TBitOver),
  215.         sizeof(TNCButton));
  216.  
  217.     CMessageBox(this, Text,
  218.         "Information Window",
  219.         MB_OK | MB_ICONINFORMATION,
  220.         GetCustWindModule());
  221. }
  222.  
  223. void TMainWindow::NCButton2(RTMessage)
  224. {
  225.     const char RegularBits[3][20] = {"BACK_FISH",
  226.         "BACK_BRICK", "BACK_SPOTWARE" };
  227.     const char MessageBits[4][20] = {"BACK_INFORMATION",
  228.         "BACK_QUESTION", "BACK_EXCLAMATION",
  229.         "BACK_STOP"};
  230.          
  231.     if(NCRadios[0]->GetState())
  232.       SetBitmap(Data, (LPSTR)MessageBits[random(4)]);
  233.     else
  234.        SetBitmap(Data, (LPSTR)RegularBits[random(3)]);
  235.  
  236.    InvalidateRect(HWindow, NULL, TRUE);
  237. }
  238.  
  239. void TMainWindow::NCRadio(RTMessage)
  240. {
  241. }
  242.  
  243.